﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace PFAGame
{
    class ProjectileSpecialist : AProjectile
    {
        Texture2D tmpTex;

        private List<AMob> mobAlreadyHit = new List<AMob>();
        private int piercingCount = 1;

        public Color color = Color.White;

        float angle;

        public int PiercingCount
        {
            get { return piercingCount; }
            set { piercingCount = value; }
        }

        public override void init()
        {
            base.init();
            obj = AObject.e_object.PROJECTILESPEC;
            tmpTex = ScreenManager.Singleton.Game.Content.Load<Texture2D>("Fireball");

            angle = (float)Math.Acos(orientation.X);
            if (orientation.Y < 0)
                angle = -angle;
        }

        public override void update(GameTime gameTime)
        {
            // deplacement dans AProjectile
            base.update(gameTime);

            // SphereCast pour tester les collisions sur la liste de joueur (projectile de mob)
            List<AObject> list = AObject.SphereCast(position + orientation * 0.25f, 0.25f, GameplayScreen.Singleton.MobList);
            if (list.Count != 0)
            {
                // si un objet est touché, on applique les dégats et on détruit le projectile
                foreach (AMob mob in list)
                {
                    if (mobAlreadyHit.Contains(mob) || mob.state == AMob.e_state.DYING)
                        continue;
                    mobAlreadyHit.Add(mob);
                    mob.receiveDammage(Dammage);
                    mob.receiveBump(orientation, 10, 0.1f);
                    --PiercingCount;
                }
                if (PiercingCount <= 0)
                    GameplayScreen.Singleton.DeleteProjectileList.Add(this);
            }
        }

        public override void draw(GameTime gameTime, Camera camera)
        {
            base.draw(gameTime, camera);
            displayRectangle.X += camera.ZoomLevel / 2;
            displayRectangle.Y += camera.ZoomLevel / 2;
            ScreenManager.Singleton.SpriteBatch.Draw(tmpTex, displayRectangle, new Rectangle(0, 0, 100, 81), color, angle, new Vector2(50, 40), SpriteEffects.None, 0);
        }
    }
}
